layui.use('layer', function() {
	window.layer = layui.layer;
	window.layui_open = layer.open;
	/**
	 * 全局加入layer,添加layer异步加载
	 * @name layer_open
	 * @param {Object} e
	 * @param {Boolean} [e.async] 如果async存在,则content按地址处理
	 * @param {Object} [e.goal=parent|top] 如果type==2,定义在哪个窗口打开parent/top/self
	 */
	window.layer.open = function(e) {
		if(e.async) {
			requires('text|' + e.content, function(html) {
				if(e.data) {
					var tpl = document.createElement("div");
					tpl.innerHTML = html;
					laytpl(tpl, e.data, function(view) {
						e.content = view;
						layui_open(e)
					});
				} else {
					e.content = html;
					return layui_open(e)
				}
			})
		} else if(e.type == 2) {
			var goal = e.goal ? e.goal : window,
				source = window;

			var _success = e.success;
			e.success = function(layero, index) {
				layero.find('iframe').get(0).contentWindow.layerSource = source;
				layero.find('iframe').get(0).contentWindow.layerIndex = index;
				console.log('当前iframe的index:window.layerIndex= ' + index);
				console.log('当前iframe的来源(parent):window.layerSource= ', source);
				_success && _success(layero, index);
			};
			goal.layui_open(e);
		} else {
			return layui_open(e);
		}
	};
});